//
//  undergroundController.h
//  ElektroM
//
//  Created by Michael on 09.10.09.
//  Copyright 2009 Artgruppe inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "controllerWithTab.h"
#import "myScroll.h"

@class showInfoWindow;
@class uStationSelector;
@class uLineSelector;
@class helpForUnderground;
@class dataBase;
@class drawingCanvas;
@class mainViewController;
@class graphCalc;

@interface undergroundController : controllerWithTab <UINavigationBarDelegate, UIScrollViewDelegate,
							UITextFieldDelegate> {
	NSString* 	databaseName;	//! contains current database name to the current railway;

	// interface stuff:
	UIImageView* 	image;	
	double 		_dyAnimation;	

	graphCalc* 	_graph;

	NSArray* 	_aiNodes;
	NSArray* 	_aiLineNumbers;

	NSArray* 	_aiCenterX;
	NSArray* 	_aiCenterY;

														
	bool _bAreWeInScrollMode;
	bool _bSightsWereShown;
	int  _nLastNumber;
	bool _bHideInfoPanelWasForced;
	bool _bTapWarningWasShown;
														
	bool _bShowFog;
														
	bool _bUpperToolbarShown;	// if the user chose the toolbar to stay on the screen
	bool _bBigToolbarWasShownBefore;
	//bool _bGoDeeperLevelYourself;
														
	NSUInteger _nFirstFoundStation;
	NSUInteger _nSecondFoundStation;			
														
	NSUInteger 	_nWhatSt;
								
	NSInteger _nCurSelectedPath;
	NSUInteger _nCountOfAllowedLines;
	
	NSArray* 	_aiDrawInfo;
	dataBase* 	_db;
	CGPoint 	_ptCenterStart;

	//iApple style of lines:
	NSArray*	_aiUStationNames;
	NSArray*	_aiULineNames;
	NSArray*	_aiiUStationIds;
	NSArray*	_aiiULineNumbers;

	// sightseeing station' ids:
	NSArray*	_aiSStationIds;
	int _nImage;
	bool _bLoadImageByLocale;

	bool _bLoadMyChild;
	// if we need to update our canvas...
	bool _bReformDrawBuffer;
	bool _bNeedToCalculateGraph; /// for calculating graph only if it's needed!
	CGPoint _ptWhereLast;
														
	bool _bBigUpBar;
	//bool _bUpToolbarHidden; // use that as the state;
	
	uStationSelector* selectStations;
	showInfoWindow* infoWindow;
	uLineSelector* linesSelector;
	helpForUnderground* helpController;
	
	IBOutlet UILabel* tapWarning;
	IBOutlet UIButton* minusSymbol;
	IBOutlet UIButton* upperShowButton;
	IBOutlet drawingCanvas* canvas;
	IBOutlet myScroll* scrollView;
	IBOutlet UIView* upperToolbar;
	IBOutlet UIView* showSightseeings;
	IBOutlet UITextField* station1;
	IBOutlet UITextField* station2;
	IBOutlet mainViewController* mainController;
	IBOutlet UILabel* timeOfJourney;
	IBOutlet UIButton* btnShowUpperPanel;
	IBOutlet UIActivityIndicatorView* busy;
}
@property (nonatomic,retain) showInfoWindow* infoWindow;
@property (nonatomic,retain) IBOutlet UILabel* timeOfJourney;
@property (nonatomic,retain) IBOutlet mainViewController* mainController;
@property (nonatomic,retain) IBOutlet UITextField* station1;
@property (nonatomic,retain) IBOutlet UITextField* station2;

@property (nonatomic,retain) NSString* databaseName;
@property (nonatomic,retain) UIImageView* image;

@property (nonatomic,retain) uStationSelector* selectStations;
@property (nonatomic,retain) helpForUnderground* helpController;

@property (nonatomic,retain) IBOutlet myScroll* scrollView;
@property (nonatomic,retain) IBOutlet UIView* upperToolbar;


-(IBAction) resetStation:(id) button;
-(IBAction) showHelp;
-(IBAction) changeBigSmallUpBar;
-(IBAction) showInfoWindow;
-(IBAction) showHideUpperPanelOnButton;

-(void)findStationInPoint:(CGPoint) ptCur;
-(void) updateInterface;

// animation stuff:
-(void) hideToolbarWithAnimationAndInfo:(int)nInfo;
-(void) showToolbarWithAnimationAndInfo:(int)nInfo;
-(void)fadeInToolbar:(NSTimer*)theTimer;
-(void)fadeOutToolbarSimple:(NSTimer*)theTimer;
-(void)fadeOutToolbar:(NSTimer*)theTimer;

-(void) recalculateGraph;
-(void) drawNodeNormalStation:(bool)bOrdinal Color:(UIColor*)color StationIndex:(int)index;
-(void) drawLineWithColor:(UIColor*)color StationIndex:(int)index;
-(void)drawArcWithColor:(UIColor*)color StationIndex:(int)index;
-(void) drawSelection;
-(void) setSelection:(int)selected;
-(void)drawLineWithColor:(UIColor*)color withPoint:(CGPoint)pt;
-(void) loadAllNeededStuff;
-(void) releaseAllStuff;
- (void)fadeInToolbarInfo:(NSTimer*)theTimer;
-(void) showToolbarInfoWithAnimationAndInfo:(int)nInfo;
- (void)fadeOutToolbarInfo:(NSTimer*)theTimer;
-(void) hideToolbarInfoWithAnimationAndInfo:(int)nInfo;
-(void) showInfoOnAnyOfStations;
-(void) performGraphCalc;
-(void) showTapWarnWithInfo:(int)nInfo;
-(void) hideTapWarnWithInfo:(int)nInfo;
-(void) hideTapWarnTmr;
-(void) drawFog;
-(void) enableUserIteraction;
-(void) disableUserIteraction;
-(void) showLoadingIndicator;
-(IBAction) showNextStation;
-(IBAction) showPrevStation;
-(void) checkIfNavigationBarIsHidden;
@end
